﻿namespace Lekce05
{
    using System;
    using System.Threading;
    using Microsoft.SPOT.Hardware;
    using SecretLabs.NETMF.Hardware.NetduinoPlus;

    public class Program
    {
        public static readonly OutputPort AlarmLed = new OutputPort(Pins.GPIO_PIN_D7, false);

        public static readonly OutputPort TamperLed = new OutputPort(Pins.GPIO_PIN_D9, false);

        public static readonly InterruptPort Tamper = new InterruptPort(Pins.GPIO_PIN_D3,false,ResistorModes.Disabled, Port.InterruptMode.InterruptEdgeBoth);
        
        public static readonly InterruptPort Alarm = new InterruptPort(Pins.GPIO_PIN_D5, false, ResistorModes.Disabled, Port.InterruptMode.InterruptEdgeBoth);

        public static void Main()
        {
            Tamper.OnInterrupt += new NativeEventHandler(Tamper_OnInterrupt);

            Alarm.OnInterrupt += new NativeEventHandler(Alarm_OnInterrupt);

            Thread.Sleep(Timeout.Infinite); 
        }

        static void Tamper_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            TamperLed.Write(data2 == 1);
        }

        static void Alarm_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            AlarmLed.Write(data2 == 1);
        }
    }
}
